<?php

declare(strict_types=1);

namespace App\Request;

use App\Support\Pattern;
use Hyperf\Validation\Request\FormRequest;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'phone' => [
                'required',
                'regex:' . Pattern::PHONE_NUMBER,
                'unique:users,phone',
            ],
            'name' => 'required|string|between:2,30',
            'password' => 'string|between:6,20',
            'nickname' => 'required|string|between:2,30',
        ];
    }

    public function attributes(): array
    {
        return [
            'phone' => '电话',
            'name' => '账号',
            'password' => '密码',
            'nickname' => '昵称'
        ];
    }
}
